package io.github.maojian.jzoffer.linkedlist;

import java.util.Stack;

/**
 * @Auther: jian.mao
 * @Date: 2022-06-22 15:33
 * @Description:
 */
public class JzOffer06 {
    public int[] reversePrint(ListNode head) {

        Stack<Integer> stack = new Stack<>();
        ListNode temp = head;
        while (temp != null) {
            stack.push(temp.val);
            temp = temp.next;
        }
        int size = stack.size();
        int[] result = new int[size];
        for (int i = 0; i < size; i++) {
            result[i] = stack.pop();
        }

        return result;
    }


}

class ListNode {
    int val;
    ListNode next;

    ListNode(int x) {
        val = x;
    }
}
